<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//会员列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$fields=array();
	$list=pdo_getslice('core_ideal_money',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=model('core/member')->basic($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员列表'),
		),
		'list'=>array('data'=>'list','key'=>'mid','total'=>$total,'psize'=>$psize,'del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'money','title'=>'当前红包余额','type'=>'string'),
			array('name'=>'total_money','title'=>'累计获得红包','type'=>'string'),
			array('name'=>'frozen_money','title'=>'冻结金额','type'=>'string'),
		),'action'=>array(
			array('type'=>'href','op'=>'inlog','title'=>'红包获得日志'),
			array('type'=>'href','op'=>'outlog','title'=>'红包提现日志'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'title'=>'会员ID','name'=>'mid','action'=>'member.get_member/'),
		),
	);
	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='inlog'){
	$mid=intval($_RQ['mid']);
	if(!$mid){
		exi('请先选择会员！','error');
	}
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$mid,
	);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$fields=array();
	$list=pdo_getslice('core_ideal_money_inlog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=model('core/member')->basic($item['mid']);
		}
	}
	$return['list']=$list;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回会员列表'),
		),
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'money','title'=>'红包金额','type'=>'string'),
			array('name'=>'createtime','title'=>'获得时间','type'=>'time'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
		)),
	);
	exi($return);
}
//提现申请列表
if($_RQ['op']=='outlog'){
	$return['params']=array();
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		//'status'=>0,
	);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$fields=array();
	$list=pdo_getslice('core_ideal_money_outlog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=model('core/member')->basic($item['mid']);
		}
	}
	$return['list']=$list;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'申请列表'),
		),
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'money','title'=>'申请提现金额','type'=>'string'),
			array('name'=>'cash_money','title'=>'实际到账金额','type'=>'string'),
			array('name'=>'createtime','title'=>'申请时间','type'=>'time'),
			array('name'=>'to_type','title'=>'提现方式','type'=>'radio','options'=>'to_types'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'order_id','title'=>'提现支付单ID','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal','op'=>'check','title'=>'审核','show'=>array('status'=>0)),
		)),
		'search'=>array(
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
			array('type'=>'choose','width'=>15,'title'=>'会员ID','name'=>'mid','action'=>'member.get_member/'),
		),
	);
	$return['to_types']=array(
		'1'=>'提现到余额',
		'2'=>'提现到微信零钱',
	);
	$return['status']=array(
		'0'=>'待打款',
		'1'=>'已打款',
		'2'=>'已拒绝',
	);
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$item=pdo_get('core_ideal_money_outlog',array('id'=>$id));
		$type=intval($post['type']);
		$status=intval($post['status']);
		if(!$status){
			exi('请先选择是否审核通过！','error');
		}
		if($status==1){
			model('core/red_pack')->pay_cash($id);
			exi('打款成功！','','outlog');
		}else{
			if(!$post['remark']){
				exi('请填写审核不通过原因！','error');
			}
			model('core/red_pack')->back_cash($id,$post['remark']);
			exi('操作成功！','','outlog');
		}
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('core_ideal_money_outlog',array('id'=>$id));
	if(!$item){
		exi('指定提现申请不存在！','error');
	}
	if($item['status']){
		exi('该提现申请已审核，请勿重复审核~','error');
	}
	
	$return['statuss']=array(
		'1'=>'审核通过并打款',
		'2'=>'审核不通过',
	);
	$return['to_types']=array(
		'1'=>'提现到余额',
		'2'=>'提现到微信零钱',
	);
	$item['to_type']=$return['to_types'][$item['to_type']];
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'copy','name'=>'to_type','title'=>'提现类型'),
			array('type'=>'copy','name'=>'money','title'=>'提现金额'),
			array('type'=>'copy','name'=>'cash_money','title'=>'真实到账金额'),
			array('type'=>'radio','name'=>'status','title'=>'审核','options'=>'statuss'),
			array('name'=>'remark','title'=>'不通过原因','type'=>'string','show'=>array('status'=>2)),
		),
	);
	exi($return);
}
if($_RQ['op']=='pay'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要打款的提现申请！','error');
	}
	model('core/red_pack')->pay_cash($id);
	exi('提现成功！');
}